#include "../source/server.hpp"

void OnConnect(const PtrConnection &conn)
{
    DBG_LOG("NEW CONNECTION:%p\n", conn.get());
}

void CloseConnect(const PtrConnection &conn)
{
    DBG_LOG("Release CONNECTION:%p\n", conn.get());
}

void OnMessage(const PtrConnection &conn, Buffer *buf)
{
    DBG_LOG("%s\n", buf->GetReadPosion());
    buf->MoveReadOffset(buf->ReadAbleSize());
    std::string str = "hello";
    conn->Send(str.c_str(), str.size());
}

int main()
{
    TcpServer tcpserver(8888);
    tcpserver.SetThreadCount(2);
    tcpserver.EnableInactiveRelease(10);
    tcpserver.SetConnectedCallback(std::bind(OnConnect,std::placeholders::_1));
    tcpserver.SetClosedCallback(std::bind(CloseConnect,std::placeholders::_1));
    tcpserver.SetMessageCallback(std::bind(OnMessage,std::placeholders::_1,std::placeholders::_2));
    tcpserver.Start();
}